package com.winning.xffw.service.quartz.manage.controller;

import com.winning.xffw.service.quartz.entity.QuartzJob;
import com.winning.xffw.service.quartz.manage.service.IJobManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定时任务job管理
 *
 * @Author: spf@winning.com.cn
 * @Description:
 * @Date 2019/06/03 17:41
 */
@Slf4j
@RestController
@RequestMapping("/jobManage")
public class JobManageController {


    @Autowired
    private IJobManageService jobManageService;

    /**
     * 新增、修改定时任务
     *
     * @param job
     * @return
     */
    @ResponseBody
    @RequestMapping("/saveJob")
    public String saveJob(QuartzJob job) {
        jobManageService.saveJob(job);
        return "处理成功！";
    }

    /**
     * 触发定时任务
     *
     * @param jobName
     * @param jobGroup
     * @return
     */
    @ResponseBody
    @RequestMapping("/triggerJob")
    public String triggerJob(String jobName, String jobGroup) {
        jobManageService.triggerJob(jobName, jobGroup);
        return "触发成功！";
    }

    /**
     * 停止定时任务
     *
     * @param jobName
     * @param jobGroup
     * @return
     */
    @ResponseBody
    @RequestMapping("/pauseJob")
    public String pauseJob(String jobName, String jobGroup) {
        jobManageService.pauseJob(jobName, jobGroup);
        return "停止成功！";
    }

    /**
     * 恢复定时任务
     *
     * @param jobName
     * @param jobGroup
     * @return
     */
    @ResponseBody
    @RequestMapping("/resumeJob")
    public String resumeJob(String jobName, String jobGroup) {
        jobManageService.resumeJob(jobName, jobGroup);
        return "恢复成功！";
    }

}